#pragma once

#include <event2/event.h>
#include <event2/listener.h>
#include <event2/buffer.h>
#include <event2/bufferevent.h>

#include <cstdio>
#include <cstring>

class Server final
{
public:
    explicit Server(sockaddr *addr);

    void Start();

private:
    static void AcceptCallback(struct evconnlistener *listener, evutil_socket_t fd, struct sockaddr *addr, int socklen, void *arg);
    static void ReadCallback(struct bufferevent *bev, void *arg);
    static void ErrorCallback(struct bufferevent *bev, short error, void *arg);

private:
    event_base *base_ = nullptr;
    evconnlistener *listener_ = nullptr;
};
